import string
from typing import Union
from fastapi import FastAPI, UploadFile
from starlette.websockets import WebSocket
from tools import *
from tools.image_tools import *

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

class Emotion:
    def __init__(self, name, probability):
        self.name = name
        self.probability = probability

@app.post("/uploadfile/")
async def create_upload_file(file: UploadFile):
    result = await deepface_analyze_file(file)
    return {
        "filename": file.filename,
        "content_type": file.content_type,
        "result": result
    }

@app.post("/ana_image/")
async def create_upload_file(file_path):
    result = await deepface_analyze_path(file_path)
    filename= file_path.split("/")[-1]
    content_type= "image/png"
    return {
        "filename": filename,
        "content_type": content_type,
        "result": result
    }

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=3939)